package com.lyb.spzx.manager.controller;

import com.github.pagehelper.PageInfo;
import com.lyb.spzx.manager.service.CategoryBrandService;
import com.lyb.spzx.model.dto.product.CategoryBrandDto;
import com.lyb.spzx.model.entity.product.Brand;
import com.lyb.spzx.model.entity.product.CategoryBrand;
import com.lyb.spzx.model.vo.common.Result;
import com.lyb.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "分类品牌管理")
@RestController
@RequestMapping("admin/product/categoryBrand")
public class CategoryBrandController {

    @Autowired
    CategoryBrandService categoryBrandService;

    @Operation(summary = "分页查询")
    @GetMapping("/findCategoryBrandByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<CategoryBrand>> findAllData(@PathVariable(value = "pageNum") Integer pageNum,
                                                       @PathVariable(value = "pageSize") Integer pageSize,
                                                       CategoryBrandDto categoryBrandDto){
        PageInfo<CategoryBrand> categoryBrandPageInfo =
                categoryBrandService.findAllDataByPage(pageNum,pageSize,categoryBrandDto);
        return Result.build(categoryBrandPageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加")
    @PostMapping("/saveCategoryBrand")
    public Result saveData(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.saveData(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改")
    @PutMapping("/updateCategoryBrand")
    public Result updateData(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.updateData(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "删除")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        categoryBrandService.deleteDataById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据分类Id查询品牌")
    @GetMapping("/findBrandByCategoryId/{categoryId}")
    public Result findBrandByCategoryId (@PathVariable Long categoryId){
        List<Brand> brands = categoryBrandService.findBrandByCategoryId(categoryId);
        return Result.build(brands,ResultCodeEnum.SUCCESS);
    }
}
